package com.czy.fx.day1.button;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/*按钮相关设置*/
public class demo1 extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("地磅管理系统");
        primaryStage.setWidth(500);
        primaryStage.setHeight(500);

        Group group = new Group();
        Scene scene = new Scene(group);
        primaryStage.setScene(scene);

        Button b1 = new Button("按钮");
        group.getChildren().add(b1);

        b1.setLayoutX(100);
        b1.setLayoutY(100);
        b1.setPrefWidth(100);
        b1.setPrefHeight(100);
        //设置字体和大小
        //b1.setFont(Font.font("宋体",10));
        //设置背景色,参数：颜色，边角圆角度数，边距
        //b1.setBackground(new Background(new BackgroundFill(Paint.valueOf("#8FBC8F"),new CornerRadii(20), new Insets(5))));
        //设置边框,参数：颜色，边框类型，边角圆角度数，边框宽度
        //b1.setBorder(new Border(new BorderStroke(Paint.valueOf("#8A2BE2"),BorderStrokeStyle.DOTTED,new CornerRadii(20),new BorderWidths(2))));

        /*css style方式设置样式*/
        b1.setStyle("-fx-background-color: #1169EE20;"+ //背景颜色
                "-fx-text-fill: #50ff23;"+ //文本颜色
                "-fx-border-color: #EE1169;"+ //边框颜色
                "-fx-border-radius: 5;"+ //边框圆角
                "-fx-background-radius: 5;"+ //背景圆角
                "-fx-background-insets: 5;"+ //边框到背景的距离
                "-fx-font-size: 15;"+ //字体大小
                "-fx-font-family: 'Segoe Print';"+ //字体
                "-fx-border-style: dotted;"+ //边框样式
                "-fx-border-width: 2;" //边框宽度
                );
        /*点击事件*/
        b1.setOnAction((event)-> {
            Object source = event.getSource();
            if (source == b1) {
                System.out.println(b1.getText());
            }
        });

        primaryStage.show();

    }
}
